# -*- coding: UTF-8 -*-
# cython: language_level=3
import requests
from tqdm import tqdm

from db.mysqldb import MysqlDB
from utils.own_tools import get_host

r = requests.post('http://1.119.14.218:22255/get_icp', json={'key': 'KJD%#&VCN437di&#h48', 'area': '浙'},
                  timeout=(3, 100)).text
# print(r)
for i in tqdm(r.split(';')):
    if not i.startswith('http'):
        i = 'http://' + i
    try:
        host = get_host(i)
        home_page = host['home_page']
        host = host['host']
        MysqlDB().add("INSERT INTO `zjifms`.`todo_urls` ( `home_page`, `host`, `status`) VALUES (%s,%s,%s)",
                      (home_page, host, 0))
    except:
        pass
